# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=jimtcl
pkgver=0.82
pkgrel=1
pkgdesc="An open-source, small footprint implementation of Tcl"
url="https://github.com/msteveb/jimtcl"
arch="all"
license="BSD-2-Clause"
depends_dev="openssl-dev>3"
makedepends="
	$depends_dev
	asciidoc
	readline-dev
	sqlite-dev
	tcl
	zlib-dev
	"
options="net"  # fix check with abuild rootbld
subpackages="$pkgname-dbg $pkgname-readline $pkgname-sqlite3 $pkgname-dev $pkgname-doc"
source="https://github.com/msteveb/jimtcl/archive/$pkgver/jimtcl-$pkgver.tar.gz
	tests-skip-exec2-3.2.patch
	tests-skip-socket.patch
	"

prepare() {
	default_prepare

	# tty tests fail on builders - no tty available there.
	rm tests/tty.test

	cp -r "$builddir" "$builddir-static"
}

build() {
	# CRTSCTS
	export CFLAGS="$CFLAGS -D_BSD_SOURCE"
	_build --shared

	cd "$builddir-static"
	_build
}

_build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname \
		--full \
		--with-mod=sqlite3,readline,rlprompt \
		"$@"
	# https://github.com/msteveb/jimtcl/issues/256
	CFLAGS="$CFLAGS -D_GNU_SOURCE=1" \
		make -j1
}

check() {
	make check
}

package() {
	make install DESTDIR="$pkgdir"

	install -m644 "$builddir-static"/libjim.a -t "$pkgdir"/usr/lib/
}

readline() {
	pkgdesc="Interface to readline and Tcl wrapper for Jim Tcl"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/jim/readline.so
	amove usr/lib/jim/rlprompt.tcl
}

sqlite3() {
	pkgdesc="Interface to sqlite3 for Jim Tcl"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/jim/sqlite3.so
}

dev() {
	default_dev
	amove usr/bin/build-jim-ext
}

sha512sums="
d0f8c8d515b9c7eee3ee2089a8fe9b8616b0541b7fca6b769132201c3a65a8216f9e8a333c6a3a4c2a8fa4754ab0c9d3c2bca3306b3b4db566d4f3e401a709fe  jimtcl-0.82.tar.gz
188df3307b0983bda5904f1ec26ba195f7cb435244bc516d4b8b5377320ab37a76f44500af6faac1e3dfee2dae8bc8f942b8543268d56aa21bd59de4d34099da  tests-skip-exec2-3.2.patch
cbc3f08d23cfe7ebd45e677a09e7178436e728a965ab7af44d6e27621049c1cdc82768c4e81397004be3486bf3f767684601ec28d3584ea14d3dde69ccdd8bdb  tests-skip-socket.patch
"
